package com.shire.shire_interface.conf;

import com.shire.shire_interface.filter.DeviceFilter;
import com.shire.shire_interface.filter.HttpServletRequestWrapperFilter;
import com.shire.shire_interface.filter.ShireCorsFilter;
import com.shire.shire_interface.filter.WxFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean corsFilterRegistration(){
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new ShireCorsFilter());
        registration.addUrlPatterns("*");
        registration.setName("corsFilter");
        registration.setOrder(1);
        return registration;
    }
    @Bean
    public FilterRegistrationBean deviceFilterRegistration(){
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new DeviceFilter());
        registration.addUrlPatterns("*.de");
        registration.setName("deviceFilter");
        registration.setOrder(4);
        return registration;
    }

    @Bean
    public FilterRegistrationBean wxFilterRegistration(){
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new WxFilter());
        registration.addUrlPatterns("*.wx");
        registration.setName("wxFilter");
        registration.setOrder(4);
        return registration;
    }

    @Bean
    public FilterRegistrationBean requestWrapperFilterRegistration(){
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new HttpServletRequestWrapperFilter());
        registration.addUrlPatterns("*.de", "*.wx");
        registration.setName("requestWrapperFilter");
        registration.setOrder(2);
        return registration;
    }
}
